In this demo, you will learn
how to customize themes into our React app using
the material library. Theming is mainly
used to provide consistency in an application with the various
typography options, colors, spacing,
transitions, and more. You can customize
and add values to the theme configuration
variables with themes such
as light and dark. Moving to the code, you have the theme.jsx file where you are importing the create
theme method from the styles folder of
the material package. Create theme accepts
various options, such as typography to
define the font-family, font size and font
family secondary. Palates to define the
color options for primary, secondary, error, warning, info, and success key. You can also define
themes such as dark and light themes using
theme configurations. After exporting,
check how to import the dark and light
themes in the app.js. To use the theme, import the theme provider component
from MUI material styles. Also import the dark theme and the light theme from
the components theme. Add the handle theme
change method to toggle between different themes based
on the user click action. Next, initialize
the current theme with an initial theme. Assign the dark theme
as the initial theme. Now, pass the
custom theme object under the theme provider that accepts the theme props to handle the toggling
between themes. Pass under the navbar
as props because the navbar contains the icon that will switch to
a different theme. Save the file and
execute the code. In the UI, there
is a light theme. You can switch to a
different theme basis by clicking the theme icon. In this way, you can customize
or add consistency to the application using theming
components. Thank you.